
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "examples.h"
#include "xrn_crypto.h"
#include "xrn_core.h"
#include "lorem_ipsum.h"

    /////////////////////////////////////////////////////
    //                   Introduction                  //
    /////////////////////////////////////////////////////
    // This code example shows how to create and       //
    // decode steganography raw for stream of bytes.   //
    //                                                 //
    // The output of this example is a raw file of     //
    // unspecified length.                             //
    /////////////////////////////////////////////////////

int steganography_raw_bytes(
 )
{

    int i;

    uint64_t num_envelop_bytes;
    uint64_t num_raw_bytes;
    uint8_t in_envelop_bytes[2048];
    uint8_t out_envelop_bytes[2048];
    uint8_t out_raw_bytes[2048];

    FILE *fp;

    /////////////
    // Logging //
    /////////////

    // Set the default logging file streams
    // errors -> stderr
    // warnings -> stdout
    // notifications -> stdout
    // debug -> stdout

    xrn_set_default_log(  );

    // To change the default logging you can use the functions below,
    // where fp is the opened file pointer
    // 
    // xrn_change_error_log( fp )
    // xrn_change_warning_log( fp )
    // xrn_change_notification_log( fp )
    // xrn_change_debug_log( fp )

    //////////////////////////
    // Initialize variables //
    //////////////////////////

    printf( "create an envelop... \n" );

    // this step should be taken from the lsbs of
    // the first steganography step

    num_envelop_bytes = 2048;
    for ( i = 0; i < num_envelop_bytes; i++ ) {
        in_envelop_bytes[i] = ( uint8_t ) ( i % 256 );
    }

    ///////////////////
    // make raw file //
    ///////////////////

    printf( "create the raw file... \n" );

    if ( XSUCCESS != xrn_make_steg_raw_bytes( ( uint8_t * ) LOREM_IPSUM_STR,    // the input stream of bytes to embedd
                                              strlen( LOREM_IPSUM_STR ),        // the length of the input stream of bytes
                                              in_envelop_bytes, // the input envelop stream of bytes
                                              num_envelop_bytes,        // the length of the input envelop stream of bytes
                                              out_envelop_bytes,        // the output envelop stream of bytes
                                              num_envelop_bytes // the length of the output envelop stream of bytes
          ) ) {
        return -1;
    }

    //////////////////////
    // extract raw file //
    //////////////////////

    printf( "extract the raw file... \n" );

    if ( XSUCCESS != xrn_extract_steg_raw_bytes( out_envelop_bytes,     // the raw stream of bytes
                                                 num_envelop_bytes,     // the length of the embedded raw stream of bytes
                                                 out_raw_bytes, // the output raw stream of bytes
                                                 num_envelop_bytes,     // the length of the output raw stream of bytes
                                                 &num_raw_bytes // the number of bytes written
          ) ) {
        return -1;
    }

    ///////////////
    // dump file //
    ///////////////

    fp = fopen( "raw.xf", "wb" );
    if ( fp == NULL ) {
        return -1;
    }

    if ( 1 != fwrite( out_raw_bytes, num_raw_bytes, 1, fp ) ) {
        fclose( fp );
        return -1;
    }

    fclose( fp );
    printf( "raw file created in cache/examples/exec/raw.xf\n" );

    return 0;

}

